<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="name"><span id="er-name"></span><br>
    <button>ok</button>
</body>
<script>
    var btn=document.getElementsByTagName('button')[0];
    var ername=document.getElementById('er-name');
    //用构造函数创建(正则表达式)
    var reg=new RegExp(/admin/i);
    //直接量创建
    var reg1=/admin/i;
    //test()判断传入的值是否包含默认值,如果包含返回true,不同返回false
    btn.onclick=function(){
    var name =document.getElementById('name');
    if (reg1.test(name.value)) {
        ername.innerHTML='账号正确';
    }else{
        ername.innerHTML='账号有误';
    }}

    //i表示不区分大小写
    var str='abcdefghi';
    //匹配规则
    var  reg2=/ab/i;
    console.log('test的结果'+reg2.test(str));
    console.log('exec的结果'+reg2.exec(str));
    //lastIndex :下一次匹配开始的查找的索引位置,可以修改和读取
    console.log(reg2.lastIndex);

    var str1='abc hjkl jIjiji bamamx';
    var reg3=/ji/gi;
    reg3.lastIndex=20;
    console.log(reg3.exec(str1));
</script>
</html>